package com.gizwits.opensource.appkit.yasystem;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.gizwits.gizwifisdk.api.GizWifiDevice;
import com.gizwits.gizwifisdk.enumration.GizWifiDeviceNetStatus;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.gizwifisdk.listener.GizWifiDeviceListener;
import com.gizwits.opensource.appkit.ControlModule.GosControlModuleBaseActivity;
import com.gizwits.opensource.appkit.ControlModule.GosDeviceControlActivity;
import com.gizwits.opensource.appkit.R;

import java.util.concurrent.ConcurrentHashMap;

public class MainActivity extends GosControlModuleBaseActivity {
    Button button1, button2, button3, button4;
    private LocalBroadcastManager localBroadcastManager;

    String data, data1;
    ImageView imageView;
    String tempdata;
    private GizWifiDevice device;
    GosControlModuleBaseActivity go;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        go = new GosControlModuleBaseActivity();
        localBroadcastManager = LocalBroadcastManager.getInstance(this);
        button1 = (Button) findViewById(R.id.btn2);
        button2 = (Button) findViewById(R.id.btn3);
        button3 = (Button) findViewById(R.id.btn4);
        button4 = (Button) findViewById(R.id.btn5);
        imageView = (ImageView) findViewById(R.id.image);

        Intent intent = getIntent();
        if (intent!=null) {
            device = (GizWifiDevice) intent.getParcelableExtra("GizWifiDevice");
        }
        button1.setOnClickListener(onClickListener);
        button2.setOnClickListener(onClickListener);
        button3.setOnClickListener(onClickListener);
        button4.setOnClickListener(onClickListener);
        imageView.setOnClickListener(onClickListener);

    }

    Button.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btn2:
                    data ="SautoE";
                    retun(data);
                    Intent intent = new Intent(MainActivity.this, Main1Activity.class);
                    intent.putExtra("Stone","false");
                    Bundle bundle1 = new Bundle();
                    bundle1.putParcelable("GizWifiDevice", device);
                    intent.putExtras(bundle1);
                    startActivity(intent);
                    break;
                case R.id.btn3:
                    data = "SmanualE";
                    retun(data);
                    Intent intent1 = new Intent(MainActivity.this, Main2Activity.class);
                    Bundle bundle3 = new Bundle();
                    bundle3.putParcelable("GizWifiDevice", device);
                    intent1.putExtras(bundle3);
                    startActivity(intent1);
                    break;
                case R.id.btn4:
                    data = "SmodifyE";
                    retun(data);
                    Intent intent2 = new Intent(MainActivity.this, Main3Activity.class);
                    Bundle bundle2 = new Bundle();
                    bundle2.putParcelable("GizWifiDevice", device);
                    intent2.putExtras(bundle2);
                    startActivity(intent2);
                    break;
                case R.id.btn5:
                    data = "SyrestE";
                    retun(data);
                    break;
                case R.id.image:
                    data = "SwindowE";
                    retun(data);
                    finish();
                    break;
                default:
                    break;
            }
        }
    };


    @Override
    protected void onDestroy() {
        data = "SwindowE";
        retun(data);;
        super.onDestroy();
    }

    public void retun(String data) {
        Intent intent = new Intent("com.example.broadcasttest.LOCAL_BROADCAST");
        intent.putExtra("key", data);
        intent.putExtra("data", true);
        localBroadcastManager.sendBroadcast(intent);
    }

    }

